// 用户关注列表

<template>
  <div class="focus">
    <myheader title="我的关注">
      <!-- 在left插槽插入内容 -->
      <span slot="left" class="iconfont iconjiantou2" @click="$router.back()"></span>
    </myheader>
    <!-- 主要内容是列表 -->
    <div class="list" v-for="value in followList" :key="value.id">
      <div class="box">
        <img :src="value.head_img" alt />
        <div class="center">
          <p>{{value.nickname}}</p>
          <span>2019年</span>
        </div>
        <span @click="cancelFollow(value.id)">取消关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import myheader from "@/components/myheader";
import { getUserfollows, unfollowUser } from "@/apis/users";
import myaxios from "@/utils/myaxios";
export default {
  components: {
    myheader,
  },
  data() {
    return {
      followList: [],
    };
  },
  async mounted() {
    this.init();
  },
  methods: {
    // 初始化
    async init() {
      // 请求用户关注数据
      let res = await getUserfollows();
      this.followList = res.data.data.map((v) => {
        // 改造数据
        v.head_img = myaxios.defaults.baseURL + v.head_img;
        return v;
      });
    },
    async cancelFollow(id) {
      let res = await unfollowUser(id);
      this.$toast.success(res.data.message);
      this.init();
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style lang="less" scoped>
.list {
  .box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 10px;
    border-bottom: 1px solid #ccc;
    > img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    > .center {
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    > span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>